﻿
using System.ComponentModel;
using System.Configuration;
using System.IO;

namespace CmdPrep.Properties
{
    public class ProgramSettings : ApplicationSettingsBase
    {
        #region Private static data
        
        private static ProgramSettings defaultInstance_ = 
            ApplicationSettingsBase.Synchronized(new ProgramSettings()) as ProgramSettings;
        
        #endregion
        #region Public events

        public delegate void ProjectSettingsChangedtHandler();
        public event ProjectSettingsChangedtHandler projectSettingsChanged;
        
        #endregion
        
        #region Public foundation
        
        public ProgramSettings()
        { 
            this.SettingsLoaded += (sender, e) => projectSettingsChanged();
            this.SettingsSaving += (sender, e) => projectSettingsChanged();
        }
        
        public static ProgramSettings Default
        {
            get { return defaultInstance_; }
        }
        
        #endregion
        
        #region Current project setting attributes
        
        [Browsable(false)]
        public FileInfo projectsFileInfo 
        { get {
            string fileName = useLiveData ? liveDataProjectsFileName : testDataProjectsFileName;
            string directoryName = useLiveData ? liveDataContentDirectoryName : testDataContentDirectoryName;
            
            return new FileInfo(directoryName + @"\" + fileName);
        } }

        [Browsable(false)]
        public DirectoryInfo rootDirectoryInfo
        { get {
            string rootDirectoryName = useLiveData ? liveDataRootDirectoryName : testDataRootDirectoryName;
            
            return new DirectoryInfo(rootDirectoryName);
        } }

        [Browsable(false)]
        public DirectoryInfo projectsContentDirectoryInfo
        { get {
            string directoryName = useLiveData ? liveDataContentDirectoryName : testDataContentDirectoryName;
            
           return new DirectoryInfo(directoryName);
        } }
        
        #endregion

        #region Project setting attributes for PropertyGrid

        [UserScopedSettingAttribute()]
        [DefaultSettingValueAttribute(@"true")]
        [DisplayName("Live data")]
        [Description("Is using program configuration for live data if true.")]
        [Category("Master setting")]
        public bool useLiveData
        {
            get { return ((bool)(this["useLiveData"])); }
            set { this["useLiveData"] = value; }
        }

        [UserScopedSettingAttribute()]
        [DefaultSettingValueAttribute(@"PROJECTS.DBF")]
        [DisplayName("Live data project file")]
        [Description("File name without path to project file.")]
        [Category("Live data")]
        public string liveDataProjectsFileName
        {
            get { return ((string)(this["liveDataProjectsFileName"])); }
            set { this["liveDataProjectsFileName"] = value; }
        }

        [UserScopedSettingAttribute()]
        [DefaultSettingValueAttribute(@"P:\ELSA\PROJ\")]
        [DisplayName("Live data content directory")]
        [Description("Path name project content directory.")]
        [Category("Live data")]
        public string liveDataContentDirectoryName
        {
            get { return ((string)(this["liveDataContentDirectoryName"])); }
            set { this["liveDataContentDirectoryName"] = value; }
        }

        [UserScopedSettingAttribute()]
        [DefaultSettingValueAttribute(@"D:\")]
        [DisplayName("Live data cmd root")]
        [Description("Path name root directory of CMD file operations.")]
        [Category("Live data")]
        public string liveDataRootDirectoryName
        {
            get { return ((string)(this["liveDataRootDirectoryName"])); }
            set { this["liveDataRootDirectoryName"] = value; }
        }

        [UserScopedSettingAttribute()]
        [DefaultSettingValueAttribute(@"PROJECTS.DBF")]
        [DisplayName("Test data project file")]
        [Description("File name without path to project file.")]
        [Category("Test data")]
        public string testDataProjectsFileName
        {
            get { return ((string)(this["testDataProjectsFileName"])); }
            set { this["testDataProjectsFileName"] = value; }
        }

        [UserScopedSettingAttribute()]
        [DefaultSettingValueAttribute(@"..\..\..\TestData\")]
        [DisplayName("Test data content directory")]
        [Description("Path name project content directory.")]
        [Category("Test data")]
        public string testDataContentDirectoryName
        {
            get { return ((string)(this["testDataContentDirectoryName"])); }
            set { this["testDataContentDirectoryName"] = value; }
        }
        
        [UserScopedSettingAttribute()]
        [DefaultSettingValueAttribute(@"C:\")]
        [DisplayName("Test data cmd root")]
        [Description("Path name root directory of CMD file operations.")]
        [Category("Test data")]
        public string testDataRootDirectoryName
        {
            get { return ((string)(this["testDataRootDirectoryName"])); }
            set { this["testDataRootDirectoryName"] = value; }
        }

        #endregion
    }
}
